package main

import (
	"fmt"
	"github.com/pkg/errors"
	"strconv"
)

/**
 * @Description
 * @Author huran
 * @Date
 * @Param
 * @return
 **/
func auto() func() int {
	local := 0
	return func() int {
		local += 1
		return local
	}
}
func deferReturn() (ret int) {
	//defer 能修改你得返回值
	defer func() {
		ret++
	}()
	fmt.Println(ret)
	return 100
}
func deferReturn2(a int) (ret int) {
	//defer 能修改你得返回值
	defer func() {
		a++
	}()
	fmt.Println(a)
	return 100
}

func A() (int, error) {
	return 0, errors.New("AA")
}

type MyInt2 int // 自定义类型 好处是可以定义方法
func (mi MyInt2) String() string {
	return strconv.Itoa(int(mi))
}
func main() {
	f := auto()
	for i := 0; i < 5; i++ {
		println(f())
	}
	println(deferReturn2(4))
	if _, err := A(); err != nil {

	}

	type MyInt = int //类型别名
	var a MyInt = 13
	fmt.Println(a)
	//自定义类型
	var b MyInt2 = 13
	var j = 23
	println(b.String())
	fmt.Println(int(b) + j)
}
